package com.iam.core.model;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.iam.core.config.RequestEnumJsonDeserialize;
import com.iam.core.entities.BasePaginationEntity;
import com.iam.core.enumhandler.MyIntegerToEnumHandler;
import com.iam.core.enums.SysLogType;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 日志
 * @TableName sys_log
 */
@TableName(value ="sys_log")
@Data
public class SysLog extends BasePaginationEntity implements Serializable {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 日志类型
     */
    @TableField(value = "log_type", typeHandler = MyIntegerToEnumHandler.class)
    @JsonDeserialize(using = RequestEnumJsonDeserialize.class)
    private SysLogType logType;

    /**
     * 日志内容
     */
    @TableField(value = "content")
    private String content;

    @TableField(exist = false)
    private Integer logTypeId;

    public SysLog() {
    }

    public SysLog(Integer logTypeId, String content) {
        this.logTypeId = logTypeId;
        this.content = content;
        this.creator = StpUtil.getLoginIdAsInt();
        this.createAt = new Date();
    }
}
